package top.lyjwn.todo.weinxin.mch.pay.impl;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.stereotype.Component;
import top.lyjwn.todo.weinxin.api.url.WXPayUrl2022;
import top.lyjwn.todo.weinxin.data.mcg2022.jsapi.JsapiOrder;
import top.lyjwn.todo.weinxin.data.mcg2022.jsapi.JsapiOrderResult;
import top.lyjwn.todo.weinxin.data.mcg2022.jsapi.JsapiRefund;
import top.lyjwn.todo.weinxin.data.mcg2022.jsapi.JsapiRefundResult;
import top.lyjwn.todo.weinxin.mch.pay.JsapiPay;
import top.lyjwn.todo.common.utils.http.HttpUtil;

/**
 * 微信支付接口的实现
 *
 * @author luoyujie
 *
 */
@Component("jsapiPay")
public class JsapiPayImpl implements JsapiPay {




	@Override
	public JsapiOrderResult jsapiOrderApi(JsapiOrder jsapiOrder) {
		String jsonString = JSONObject.toJSONString(jsapiOrder);
		String result = HttpUtil.request(WXPayUrl2022.JSAPI_ORDER, "POST", jsonString);
		JsapiOrderResult jsapiOrderResult = JSONObject.parseObject(result, JsapiOrderResult.class);
		return jsapiOrderResult;
	}

	@Override
	public JsapiRefundResult JsapiRefundApi(JsapiRefund jsapiRefund) {
		String jsonString = JSONObject.toJSONString(jsapiRefund);
		String result = HttpUtil.request(WXPayUrl2022.JSAPI_REFUND, "POST", jsonString);
		JsapiRefundResult jsapiRefundResult = JSONObject.parseObject(result, JsapiRefundResult.class);
		return jsapiRefundResult;
	}
}
